﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Mindmap_Case_4
{
    public partial class InputBox : Form
    {
        public InputBox()
        {
            InitializeComponent();
        }

        private string text;
        public string GetText
        {
            get { return text; }
        }

        /// <summary>
        /// Set text that already exists in the current selected control.
        /// </summary>
        /// <param name="text">Current text</param>
        public void SetPreviewText(string text)
        {
            tbInput.Text = text;
        }

        /// <summary>
        /// Sets the text and dialog result.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            text = tbInput.Text;
            this.DialogResult = DialogResult.OK;
        }

        /// <summary>
        /// Checks for an Enter event. When this occurs, the OK-btn will be triggered.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tbInput_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnOK_Click((object)sender, (EventArgs)e);
            }
            else if (e.KeyCode == Keys.Escape)
            {
                this.DialogResult = DialogResult.Cancel;
            }
        }                
    }
}
